package com.logic.modular.game.battle.panel;

import cn.hutool.core.date.DateTime;
import cn.hutool.extra.spring.SpringUtil;
import com.logic.comment.util.RedisUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 战斗流程
 */
@Slf4j
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Battle implements Serializable {
    @ApiModelProperty("对局id")
    private Long matchId;
    @ApiModelProperty("战斗编号")
    private String battleUUID;
    @ApiModelProperty("当前战斗id")
    private Long battleId;
    @ApiModelProperty("场次")
    private Integer venue = 1;
    @ApiModelProperty("当前回合数")
    private Integer round = 0;
    @ApiModelProperty("当前阶段 ")
    private Integer phase;
    @ApiModelProperty("当前事件")
    private Integer event;

    @ApiModelProperty("战斗开始时间")
    private DateTime dateTime;


    public void save() {
        RedisUtils.redisUtils().set("battle:" + battleUUID + ":", this, 30L, TimeUnit.MINUTES);
    }

    public static Battle get(String battleUUID) {
        RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
        return (Battle) redisUtils.get("battle:" + battleUUID + ":");
    }

    public void logBattle() {
        log.info("=========================" +
                        "-战斗编号:{},场次:{},战斗id:{}" +
                        "========================="
                , battleUUID, venue , battleId
        );
    }

    public void addRound() {
        round++;
        this.save();
    }
}